/**
 * Copyright 2015 厦门市合趣息科技有限公司 (http://www.hequ.info). All rights reserved.
 * Encoding UTF-8
 * Version: 1.0
 * Date: 2015-4-8
 * History:	
 */

package com.kzc.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.kzc.domain.Admin;
import com.kzc.utils.DBUtil;


/**
 *
 * @author 柯尊诚 (kezuncheng@hequ.info)
 * @version Revision: 1.0.0 Date: 2015-4-8
 */
public class AdminDaoImpl implements AdminDao {


    @Override
    public Admin find(String username, String password) {
        String sql = "select * from t_admin where username=? and password=?";
        List values = new ArrayList();
        values.add(username);
        values.add(password);
        ResultSet rs = DBUtil.query(sql, values);
        Admin admin = new Admin();
        try {
            if (rs.next()) {
                admin.setId(rs.getString("id"));
                admin.setUsername(rs.getString("username"));
                admin.setPassword(rs.getString("password"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                DBUtil.closeConnection(rs.getStatement().getConnection(), rs.getStatement(), rs);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        return admin;
        }
    }

}
